#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

struct Edge
{
  int u;
  int v;
  unsigned int w;
  int use;
};

struct EdgeLink
{
  Edge* pEdge;
  EdgeLink* pNext;
};

int list[100000][2];
Edge edgepool[100000];
Edge* edgepool_alloc;
EdgeLink linkpool[200000];
EdgeLink* linkpool_alloc;
EdgeLink* linkhash[100000];


void add( int u, Edge* pe )
{
  EdgeLink* pLink = linkpool_alloc++;
  pLink->pEdge = pe;
  pLink->pNext = linkhash[u];
  linkhash[u] = pLink;
}

struct TrieNode
{
  int next[2];
  unsigned int value;
  TrieNode()
  {
    next[0] = -1;
    next[1] = -1;
    value = 0;
  }
};

inline int getbit( unsigned int k, int p )
{
  return ( k >> p ) & 0x01;
}

unsigned int maxweight( const vector<unsigned int>& nums )
{
  vector<TrieNode> tries;
  tries.push_back( TrieNode() );
  for( size_t i = 0; i < nums.size(); i++ )
  {
    int p = 0;
    for( int j = 30; j >= 0; j-- )
    {
      int d = getbit( nums[i], j );
      if( tries[p].next[d] == -1 )
      {
        tries.push_back( TrieNode() );
        tries[p].next[d] = tries.size() - 1;
      }
      p = tries[p].next[d];
    }
    tries[p].value = nums[i];
  }
  
  int max_weight = 0;
  for( size_t i = 0; i < nums.size(); i++ )
  {
    int p = 0;
    for( int j = 30; j >= 0; j-- )
    {
      int d = getbit( ~nums[i], j );
      if( tries[p].next[d] != -1 )
      {
        p = tries[p].next[d];
      }
      else
      {
        p = tries[p].next[1 - d];
      }
    }
    int weight = nums[i] ^ tries[p].value;
    //printf( "%d^%d=%d\n", nums[i], tries[p].value, weight );
    if( max_weight < weight ) max_weight = weight;
  }
 
  return max_weight;
}

int main()
{
  while(1)
  {
    int n = 0;
    if( scanf( "%d", &n ) != 1 )
    {
      break;
    }
    memset( edgepool, 0, sizeof(edgepool) );
    edgepool_alloc = edgepool;
    memset( list, 0, sizeof(list) );
    memset( linkhash, 0, sizeof(linkhash) );
    memset( linkpool, 0, sizeof(linkpool) );
    linkpool_alloc = linkpool;
    for( int i = 0; i < n - 1; i++ )
    {
      Edge* pe = edgepool_alloc++;
      scanf( "%d %d %d", &pe->u, &pe->v, &pe->w );
      add( pe->u, pe );
      add( pe->v, pe );
    }
   
//BFS
    vector<unsigned int> weights( n, 0 );    
    list[0][0] = 0;
    list[0][1] = 0;
    size_t p = 0;   
    size_t q = 1;
    while( p < q )
    {
      int u = list[p][0];
      EdgeLink* pLink = linkhash[u];
      while( pLink != NULL )
      {
        Edge* pe = pLink->pEdge;
        if( 0 == pe->use )
        {
          pe->use = 1;
          int w = pe->w ^ list[p][1];
          int v = ( u != pe->u ) ? pe->u : pe->v;
          weights[v] = w;
          list[q][0] = v;
          list[q][1] = w;
          q++;
        }
        pLink = pLink->pNext;        
      }
      p++;
    }
//
    printf( "%u\n", maxweight( weights ) );  
  }
  return 0;
}
